#------------------------------------------------------------------------------------------------------#
#------------------------------------Portmann & Stojanovic 2017----------------------------------------#
#-----------------------------------------Political Behavior-------------------------------------------#
#------------------------Electoral discrimination against immigrant-origin candidates------------------#
#------------------------------------------------------------------------------------------------------#

#-------------- PACKAGES

want = c("readstata13", "MASS", "ggplot2", "R2admb", "texreg", "Hmisc", "plyr", "glmmADMB", "WWGbook", "lme4", "boot", "dplyr",
         "tidyr", "knitr", "SciViews")
have = want %in% rownames(installed.packages())
if ( any(!have) ) { install.packages( want[!have] ) }

# load packages
junk <- lapply(want, library, character.only = TRUE)
rm(have,want,junk)

#-------------- MANUALLY DEFINED FUNCTIONS

#--- Coefficient plot

PlotCoefficients <- function(z) {
  z <- ggplot(allModelFrame, aes(colour = Model))
  z <- z + geom_hline(yintercept = 0, colour = gray(1/2), lty = 5)
  z <- z + geom_linerange(aes(x = Variable, ymin = Coefficient - SE*interval1,
                              ymax = Coefficient + SE*interval1),
                          lwd = 0.8, position = position_dodge(width = 0.7))
  z <- z + geom_pointrange(aes(x = Variable, y = Coefficient, ymin = Coefficient - SE*interval1,
                               ymax = Coefficient + SE*interval1, shape = Model),
                           lwd = 0.4, position = position_dodge(width = 0.7)
                           #shape = c(3, 2, 1)
  )
  z <- z  + theme_bw() + coord_flip()
  z <- z + ggtitle("")
  return (z)}

#-------------- RUNNING ALL ANALYSES

setwd(".../...")

source("01-clean-data-PortmannStojanovic.r")
source("02-table-3-PortmannStojanovic.r")
source("03-figure-1-PortmannStojanovic.r")
source("04-table-5-PortmannStojanovic.r")
source("05-table-6-PortmannStojanovic.r")
source("06-figure-2-PortmannStojanovic.r")
source("07-table-7-PortmannStojanovic.r")
source("08-table-8-PortmannStojanovic.r")
source("09-table-9-PortmannStojanovic.r")
source("10-table-10-PortmannStojanovic.r")
source("11-table-11-PortmannStojanovic.r")
